const i18n = {
    'zh': {
    'title': 'PixelMug-download',
    'appName': 'PixelMug',
        'slogan': '互动无界 极致物联',
        'description1': '基于即时通讯架构设计，实时在线',
        'description2': '创新互动模式，更自然的物端操控体验',
        'downloadBtn': '下载',
        'browserTip': '点击右上角按钮，在弹出的菜单中选择"在浏览器打开"，即可下载安装',
        'feature1Title': '实时在线',
        'feature1Desc': '基于即时通讯的方式，人与设备实时在线， 想聊就聊，想用就用。',
        // 'feature2Title': '人机互动',
        // 'feature2Desc': '随时随地，人与设备直接互动，更友好、更自然。',
        'feature3Title': '亲友共享',
        'feature3Desc': '通过分享功能，可以将设备共享给自己的好友与家人。',
        'feature4Title': '智能场景',
        'feature4Desc': '场景随心设置，一条指令实现多设备协同工作，满足个性化场景需求。',
        // 'feature5Title': '指令消息',
        // 'feature5Desc': '消息即命令，还能自由组合和定义。',
        'feature2Title': '小应用扩展',
        'feature2Desc': '开放的小应用市场，实现设备能力弹性扩展，玩法更丰富。',
        'legal1': '用户同意协议',
        'legal2': '物栖隐私协议',
        'legal3': '账号注销协议',
        'legal4': '服务条款',
        'legal5': '账号注销协议'
    },
    'en': {
        'title': 'PixelMug - Download Page',
      'appName': 'PixelMug',
        'slogan': 'Connected Everywhere',
        'description1': 'Instantly Connected',
        'description2': 'Smart Control, Effortless Use',
        'downloadBtn': 'Download', // 优化：更简洁
        'browserTip': 'Tap "Open in Browser" to install.',
        'feature1Title': 'Connected',
        'feature1Desc': 'Instant connection. Chat & control anytime.',
        // 'feature2Title': 'Interaction',
        // 'feature2Desc': 'Smooth, natural device interaction.',
        'feature3Title': 'Sharing',
        'feature3Desc': 'Easily share devices with loved ones.',
        'feature4Title': 'Scenes',
        'feature4Desc': 'One tap for multi-device automation.',
        // 'feature5Title': 'Command',
        // 'feature5Desc': 'Turn messages into custom commands.',
        'feature2Title': 'Mini Apps',
        'feature2Desc': 'Expand features with smart applets.',
      'legal1': 'User Consent Agreement', // 优化：更简洁
      'legal2': 'Privacy', // 优化：极致简洁，常用缩写
      'legal3': ' Account Cancellation', // 优化：极致简洁，常用缩写
        'legal4': 'Terms', // 优化：极致简洁，常用缩写
        'legal5': 'Account Cancellation' // 优化：更简洁
      },
        'fr': {
          'title': 'PixelMug', // 优化：更简洁的标题
          'appName': 'PixelMug',
        'slogan': 'Connecté Partout',
        'description1': 'Connexion Instantanée',
        'description2': 'Contrôle Intelligent, Utilisation Fluide',
        'downloadBtn': 'Télécharger', // 优化：更简洁
        'browserTip': 'Tapez sur "Ouvrir dans le navigateur" pour installer.',
        'feature1Title': 'Connecté',
        'feature1Desc': 'Connexion instantanée. Discutez et contrôlez à tout moment.',
        // 'feature2Title': 'Interaction',
        // 'feature2Desc': 'Interaction fluide et naturelle avec les appareils.',
        'feature3Title': 'Partage',
        'feature3Desc': 'Partagez facilement vos appareils avec vos proches.',
        'feature4Title': 'Scènes',
        'feature4Desc': 'Un tap pour automatiser plusieurs appareils.',
        // 'feature5Title': 'Commandes',
        // 'feature5Desc': 'Transformez les messages en commandes personnalisées.',
        'feature2Title': 'Mini Apps',
        'feature2Desc': 'Développez les fonctionnalités avec des mini-applications.',
          'legal1': "Contrat d'utilisateur",
        'legal2': 'Légal',
          'legal3': 'Annulation de Compte',
        'legal4': 'Conditions',
        'legal5': '',

     },
        'de': {
          'title': 'PixelMug - Download-Seite',
          'appName': 'PixelMug',
            'slogan': 'Überall Verbunden',
            'description1': 'Sofort Verbunden',
            'description2': 'Intelligente Steuerung, Mühelose Nutzung',
            'downloadBtn': 'Herunterladen',
            'browserTip': 'Tippen Sie auf "Im Browser öffnen" zum Installieren.',
            'feature1Title': 'Verbunden',
            'feature1Desc': 'Sofort verbunden. Chatten und steuern jederzeit.',
            // 'feature2Title': 'Interaktion',
            // 'feature2Desc': 'Reibungslose, natürliche Geräteinteraktion.',
            'feature3Title': 'Teilen',
            'feature3Desc': 'Teilen Sie Geräte einfach mit Ihren Liebsten.',
            'feature4Title': 'Szenen',
            'feature4Desc': 'Ein Tipp für die Automatisierung mehrerer Geräte.',
            // 'feature5Title': 'Befehle',
            // 'feature5Desc': 'Verwandeln Sie Nachrichten in benutzerdefinierte Befehle.',
            'feature2Title': 'Mini Apps',
            'feature2Desc': 'Erweitern Sie Funktionen mit Mini-Apps.',
          'legal1': 'Соглашение пользователя',
            'legal2': 'Rechtliches',
          'legal3': 'Kontolöschung',
            'legal4': 'Bedingungen',
            'legal5': '',
        },
};

// 获取浏览器语言
function getBrowserLanguage() {
    const language = (navigator.browserLanguage || navigator.language).toLowerCase();
    if (language.startsWith('zh')) return 'zh';
    if (language.startsWith('fr')) return 'fr';
    if (language.startsWith('de')) return 'de';
    return 'en';
}

// 当前语言
let currentLang = getBrowserLanguage();

// 切换语言
function switchLanguage(lang) {
  if (!i18n[lang]) return;
  currentLang = lang;
  updatePageText();

  // 根据语言切换 banner 图片
  const bannerImg = document.querySelector(".banner-left-box");
  const elementsToHide = document.querySelectorAll(".hide-zh");
  let privateElements = document.getElementById("privacy-id");
  if (bannerImg) {
    if (lang === "zh") {
      bannerImg.src = "./assets/image/冒泡展示图.svg";
          elementsToHide.forEach((el) => (el.style.display = ""));
          privateElements.href =
            "https://app.jeejio.com/agreements/privacy.html";
    } else {
      bannerImg.src = "./assets/image/banner-left-img-en.png";
          elementsToHide.forEach((el) => (el.style.display = "none"));

          privateElements.href =
            "https://depository.jeejio.com/util/privacy.html";
    }
  }

}

// 获取翻译文本
function getTranslation(key) {

  // 根据语言切换 banner 图片
  const bannerImg = document.querySelector(".banner-left-box");
  const elementsToHide = document.querySelectorAll(".hide-zh");
  let privateElements = document.getElementById("privacy-id");
  if (bannerImg) {
    if (currentLang === "zh") {
      bannerImg.src = "./assets/image/冒泡展示图.svg";
      elementsToHide.forEach((el) => (el.style.display = ""));
      privateElements.href = "https://app.jeejio.com/agreements/privacy.html";
    } else {
      bannerImg.src = "./assets/image/banner-left-img-en.png";
      elementsToHide.forEach((el) => (el.style.display = "none"));

      privateElements.href = "https://depository.jeejio.com/util/privacy.html";
    }
  }
  if (!i18n[currentLang][key]) {
    return;
  }
  return i18n[currentLang][key] || i18n["en"][key] || key;
}

// 更新页面文本
function updatePageText() {
    // 更新标题
    document.title = getTranslation('title');
    
    // 更新应用名称
    document.getElementById('title').textContent = getTranslation('appName');
    
    // 更新口号和描述
    document.querySelectorAll('#oneId').forEach(el => el.textContent = getTranslation('slogan'));
    document.querySelectorAll('#twoId').forEach(el => {
        if (el.classList.contains('right-two-box')) {
            el.textContent = getTranslation('description1');
        } else {
            el.innerHTML = `${getTranslation('description1')}<br/>${getTranslation('description2')}`;
        }
    });
    document.getElementById('thereId').textContent = getTranslation('description2');
    
    // 更新下载按钮
    document.querySelectorAll('#iosId, #androidId').forEach(el => el.textContent = getTranslation('downloadBtn'));
    
    // 更新浏览器提示
    document.querySelector('.tips-content-box').innerHTML = getTranslation('browserTip').replace('"在浏览器打开"', '<span class="browser-box">在浏览器打开</span>');
    
    // 更新特性描述
    const features = document.querySelectorAll('.device-name-box');
    features[0].textContent = getTranslation('feature1Title');
    features[1].textContent = getTranslation('feature2Title');
    features[2].textContent = getTranslation('feature3Title');
    features[3].textContent = getTranslation('feature4Title');


    // features[4].textContent = getTranslation('feature5Title');
    // features[5].textContent = getTranslation('feature6Title');
    
    const descriptions = document.querySelectorAll('.device-describe-box');
    descriptions[0].textContent = getTranslation('feature1Desc');
    descriptions[1].textContent = getTranslation('feature2Desc');
    descriptions[2].textContent = getTranslation('feature3Desc');
    descriptions[3].textContent = getTranslation('feature4Desc');
    // descriptions[4].textContent = getTranslation('feature5Desc');
    // descriptions[5].textContent = getTranslation('feature6Desc');

    // 更新底部链接对应文字内容
    const legalLinks = document.querySelectorAll('.bottom-one-box a');
    console.log(legalLinks, "legalLinks");
    legalLinks[0].textContent = getTranslation('legal1');
    legalLinks[1].textContent = getTranslation('legal2');
    legalLinks[2].textContent = getTranslation('legal3');
    // legalLinks[3].textContent = getTranslation('legal4');
    // legalLinks[4].textContent = getTranslation('legal5');



}